home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / dlgds411.zip / PASRSRC.PAS < prev    next >
Pascal/Delphi Source File  |  1993-08-03  |  10KB  |  424 lines

  1. {$A-,B-,E+,F-,G-,I+,N-,O-,P-,Q-,R-,S-,T-,V-,X+}
  2. {$M 16384,5000,655360}
  3.  
  4. Program ScriptToResource;
  5.  
  6. uses Dos, Memory, Objects, Drivers, Views, Dialogs,
  7.      Editors, ColorTxt, InpLong, Validate, ReadScpt;
  8.  
  9. var
  10.   Dlg : PDialog;     {holds the dialog as it's constructed and controls added}
  11.   Control : PView;
  12.   HScrollBar : PScrollBar;
  13.  
  14. procedure Error(const S : string);
  15. begin
  16. WriteLn(S);
  17. Halt(1);
  18. end;
  19.  
  20. procedure DoOptionsEtc(P : PView; S : PScriptRec);
  21. begin
  22. with S^, MainBlock, P^ do
  23.   begin
  24.   Options := Optns;
  25.   EventMask := EvMsk;
  26.   HelpCtx := HCtx;
  27.   GrowMode := Grow;
  28.   end;
  29. end;
  30.  
  31. procedure DoButton(P : PScriptRec);
  32. var
  33.   R : TRect;
  34. begin
  35. with P^, MainBlock do
  36.   begin
  37.   R.Assign(X1, Y1, X2, Y2);
  38.   Control := New(PButton, Init(R, ButtonText^, CommandValue, Flags));
  39.   if Control <> Nil then
  40.     begin
  41.     DoOptionsEtc(Control, P);
  42.     Dlg^.Insert(Control);
  43.     end
  44.   else
  45.     Error('Cannot construct TButton');
  46.   end;
  47. end;
  48.  
  49. procedure DoListBox(P : PScriptRec);
  50. var
  51.   R : TRect;
  52. begin
  53. with P^, MainBlock do
  54.   begin
  55.   R.Assign(X1, Y1, X2, Y2);
  56.   if ScrollBar^ <> '' then
  57.     Control := New(PListBox, Init(R, Columns, PScrollBar(Control)))
  58.   else Control := New(PListBox, Init(R, Columns, Nil));
  59.   if Control <> Nil then
  60.     begin
  61.     DoOptionsEtc(Control, P);
  62.     Dlg^.Insert(Control);
  63.     end
  64.   else
  65.     Error('Cannot construct TListBox');
  66.   end;
  67. end;
  68.  
  69. procedure DoCheckRadio(P : PScriptRec);
  70. var
  71.   R : TRect;
  72.   LastItem : PSItem;
  73.   I : integer;
  74.  
  75. begin
  76. with P^, MainBlock do
  77.   begin
  78.   R.Assign(X1, Y1, X2, Y2);
  79.   LastItem := Nil;
  80.   for I := Items-1 downto 0 do  {this has to be done backwards}
  81.     LastItem := NewSItem(PString(LabelColl^.At(I))^, LastItem);
  82.   case Kind of
  83.     CheckB:
  84.       Control := New(PCheckBoxes, Init(R, LastItem));
  85.     RadioB:
  86.       Control := New(PRadioButtons, Init(R, LastItem));
  87.     MultiCB:
  88.       Control := New(PMultiCheckBoxes, Init(R, LastItem, SelRange,
  89.                  MCBFlags, States^));
  90.     end;
  91.   if Control <> Nil then
  92.     begin
  93.     DoOptionsEtc(Control, P);
  94.     PCluster(Control)^.SetButtonState(not Mask, False);
  95.     Dlg^.Insert(Control);
  96.     end
  97.   else
  98.   case Kind of
  99.     CheckB:
  100.       Error('Cannot construct TCheckBoxes');
  101.     RadioB:
  102.       Error('Cannot construct TRadioButtons');
  103.     MultiCB:
  104.       Error('Cannot construct TMultiCheckBoxes');
  105.     end;
  106.   end;
  107. end;
  108.  
  109. procedure DoInputLong(P : PScriptRec);
  110. var
  111.   R : TRect;
  112. begin
  113. with P^, MainBlock do
  114.   begin
  115.   R.Assign(X1, Y1, X2, Y2);
  116.   Control := New(PInputLong, Init(R, LongStrLeng, LLim, ULim, ILOptions));
  117.   if Control <> Nil then
  118.     begin
  119.     DoOptionsEtc(Control, P);
  120.     Dlg^.Insert(Control);
  121.     end
  122.   else
  123.     Error('Cannot construct TInputLong');
  124.   end;
  125. end;
  126.  
  127. procedure DoStaticText(P : PScriptRec);
  128. var
  129.   R : TRect;
  130. begin
  131. with P^, MainBlock do
  132.   begin
  133.   R.Assign(X1, Y1, X2, Y2);
  134.   case Kind of
  135.     SText :
  136.       Control := New(PStaticText, Init(R, Text^));
  137.     CText :
  138.       Control := New(PColoredText, Init(R, Text^, Attrib));
  139.     end;
  140.   if Control <> Nil then
  141.     begin
  142.     DoOptionsEtc(Control, P);
  143.     Dlg^.Insert(Control);
  144.     end
  145.   else
  146.     Error('Cannot construct '+BaseObj^);
  147.   end;
  148. end;
  149.  
  150. procedure DoMemo(P : PScriptRec);
  151. var
  152.   R : TRect;
  153.   Vbar, Hbar : PScrollBar;
  154. begin
  155. with P^, MainBlock do
  156.   begin
  157.   R.Assign(X1, Y1, X2, Y2);
  158.   if VScroll^ <> '' then VBar := PScrollBar(Control)
  159.     else VBar := Nil;
  160.   if HScroll^ <> '' then HBar := HScrollBar
  161.     else HBar := Nil;
  162.  
  163.   Control := New(PMemo, Init(R, Hbar, Vbar, Nil, BufSize));
  164.   if Control <> Nil then
  165.     begin
  166.     DoOptionsEtc(Control, P);
  167.     Dlg^.Insert(Control);
  168.     end
  169.   else
  170.     Error('Cannot construct TMemo');
  171.   end;
  172. end;
  173.  
  174. procedure DoLabel(P : PScriptRec);
  175. var
  176.   R : TRect;
  177.   Labl : PLabel;
  178. begin
  179. with P^, MainBlock do
  180.   begin
  181.   R.Assign(X1, Y1, X2, Y2);
  182.   Labl := New(PLabel, Init(R, LabelText^, Control));
  183.   if Labl <> Nil then
  184.     begin
  185.     DoOptionsEtc(Labl, P);
  186.     Dlg^.Insert(Labl);
  187.     end
  188.   else
  189.     Error('Cannot construct TLabel');
  190.   end;
  191. end;
  192.  
  193. procedure DoScrollBar(P : PScriptRec);
  194. var
  195.   R : TRect;
  196.   Tmp : PScrollBar;
  197. begin
  198. with P^, MainBlock do
  199.   begin
  200.   R.Assign(X1, Y1, X2, Y2);
  201.   Tmp := New(PScrollBar, Init(R));
  202.   if Tmp <> Nil then
  203.     begin
  204.     DoOptionsEtc(Tmp, P);
  205.     Dlg^.Insert(Tmp);
  206.     if SameString(VarName^, 'HScroll') then
  207.       HScrollBar := Tmp     {probably a horizontal scrollbar for TMemo}
  208.     else Control := Tmp;
  209.     end
  210.   else
  211.     Error('Cannot construct TScrollBar');
  212.   end;
  213. end;
  214.  
  215. procedure DoHistory(P : PScriptRec);
  216. var
  217.   R : TRect;
  218.   History : PHistory;
  219. begin
  220. with P^, MainBlock do
  221.   begin
  222.   R.Assign(X1, Y1, X2, Y2);
  223.   History := New(PHistory, Init(R, PInputLine(Control), HistoryID));
  224.   if History <> Nil then
  225.     begin
  226.     DoOptionsEtc(History, P);
  227.     Dlg^.Insert(History);
  228.     end
  229.   else
  230.     Error('Cannot construct THistory');
  231.   end;
  232. end;
  233.  
  234. procedure DoInputLine(P : PScriptRec);
  235. var
  236.   R : TRect;
  237.   Val : PValidator;
  238. begin
  239. with P^, MainBlock do
  240.   begin
  241.   R.Assign(X1, Y1, X2, Y2);
  242.   Control := New(PInputLine, Init(R, StringLeng));
  243.   if Control <> Nil then
  244.     begin
  245.     DoOptionsEtc(Control, P);
  246.     Dlg^.Insert(Control);
  247.    if ValKind in [Picture..StringLookup] then
  248.       begin
  249.       Val := Nil;
  250.       case ValKind of
  251.         Picture:
  252.            Val := New(PPXPictureValidator, Init(PictureString^, AutoFill <> 0));
  253.         Range:
  254.            begin
  255.            Val := New(PRangeValidator, Init(LowLim, UpLim));
  256.            if (Val <> Nil) and (Transfer <> 0) then
  257.              Val^.Options := voTransfer;
  258.            end;
  259.         Filter:
  260.            Val := New(PFilterValidator, Init(TCharSet(ActualCharSet)));
  261.         StringLookup:
  262.            Val := New(PStringLookupValidator, Init(Nil));
  263.         end;
  264.       if Val <> Nil then PInputLine(Control)^.Validator := Val
  265.       else Error('Cannot construct Validator');
  266.       end;
  267.     end
  268.   else
  269.     Error('Cannot construct TInputLine');
  270.   end;
  271. end;
  272.  
  273. procedure DoDialog;
  274. var
  275.   R : TRect;
  276. begin
  277. with Dialog^, MainBlock do
  278.   begin
  279.   R.Assign(X1, Y1, X2, Y2);
  280.   Dlg := New(PDialog, Init(R, Title^));
  281.   if Dlg <> Nil then
  282.     begin
  283.     DoOptionsEtc(Dlg, Dialog);
  284.     Dlg^.Palette := Dialog^.Palette;
  285.     Dlg^.Flags := Dialog^.WinFlags;
  286.     end
  287.   else
  288.     Error('Cannot construct Dialog');
  289.   end;
  290. end;
  291.  
  292. procedure MakeResource;
  293.   procedure DoControls(P : PScriptRec); far;
  294.   begin
  295.   case P^.Kind of
  296.     Button: DoButton(P);
  297.     InputL: DoInputLine(P);
  298.     Labl: DoLabel(P);
  299.     Histry: DoHistory(P);
  300.     ILong: DoInputLong(P);
  301.     CheckB, RadioB, MultiCB:
  302.            DoCheckRadio(P);
  303.     ListB: DoListBox(P);
  304.     ScrollB: DoScrollBar(P);
  305.     Memo:  DoMemo(P);
  306.     CText, SText: DoStaticText(P);
  307.     end;
  308.   end;
  309.  
  310. begin
  311. DoDialog;
  312. ScriptColl^.ForEach(@DoControls);
  313. Dlg^.SelectNext(False);
  314. end;
  315.  
  316. procedure WriteResource;
  317. var
  318.   Strm, StrmBKP : PBufStream;
  319.   Rsrc : TResourceFile;
  320.   FileNameBKP, S : PathStr;
  321.   Name : NameStr;
  322.   Ext : ExtStr;
  323.   F : File;
  324.   IOR, Value : Word;
  325.   Check1 : Array[1..4] of char;
  326.   Check2 : Array[1..2] of char absolute Check1;
  327.  
  328. begin
  329. MakeResource;   {dialog is now in 'Dlg'}
  330.  
  331. S :=  DefaultExt( ParamStr(2), '.REZ');
  332. if FSearch(S, '') <> '' then
  333.   begin
  334.   {$I-}
  335.   Assign(F, S);
  336.   Reset(F,1);
  337.   if IOResult <> 0 then
  338.       Error('Could not open '+S);
  339.   BlockRead(F, Check1, Sizeof(Check1));
  340.   {EXE files start with 'MZ'}
  341.   if Check2 = 'MZ' then     {Check2 has same address as Check1}
  342.     begin       {an EXE file}
  343.     Seek(F, $18);
  344.     BlockRead(F, Value, Sizeof(Value));
  345.     Close(F);
  346. {$ifdef DPMI}
  347.     if Value < $40 then
  348.       Error('Can''t write resource to old type EXE file');
  349. {$else}
  350.     if Value >= $40 then
  351.       Error('Can''t write resource to new type EXE file (DPMI or Windows)');
  352. {$endif}
  353.     end
  354.   else if Check1 <> 'FBPR' then {REZ files start with 'FBPR'}
  355.     Error('File exists but is not a resource or EXE file');
  356.  
  357.   {Back up the existing file}
  358.   FSplit(S, FileNameBKP, Name, Ext);
  359.   FileNameBKP := FileNameBKP + Na